﻿package cn.poco.pepsi.service.impl;

import java.io.InputStream;
import java.util.List;

import android.util.Log;
import cn.poco.pepsi.bean.Restaurant;
import cn.poco.pepsi.service.INear;
import cn.poco.pepsi.util.UrlConnectionUtil;
import cn.poco.pepsi.util.UrlMatchUtil;
import cn.poco.pepsi.util.xmlpared.RestaurantXmlparse;


public class NearImpl implements INear {

	private final static String TAG = "NearImpl";

	@Override
	public List<Restaurant> getResByGps(String citycode, String lat, String lon, int s, int l, Integer dis, Integer vouch,
			String dish, String d) throws Exception {
		InputStream inStream = null;
		StringBuffer sb = new StringBuffer();
			sb.append(BASE_GPS_RES_PATH);
			if(lat!=null){
				sb.append("?lat=").append(lat);
			}
			if(lon!=null){
				sb.append("&long=").append(lon);
			}
			if(citycode!=null && !citycode.equals("")){
				sb.append("&cd=").append(citycode);
			}
			if(s>=0){
				sb.append("&s=").append(s);
			}
			if(l>=0){
				sb.append("&l=").append(l);
			}
			if(dis!=null){
				sb.append("&dis=").append(dis);
			}
			if(vouch!=null){
				sb.append("&vouch=").append(vouch);
			}
			if(dish!=null){
				sb.append("&dish=").append(dish);
			}
			if(d!=null){
				sb.append("&d=").append(d);
			}
			String path=UrlMatchUtil.matchUrl(sb.toString());
			Log.i(TAG,path);
			inStream = UrlConnectionUtil.getRequest(path);
			return RestaurantXmlparse.getXml(inStream);
	}
	
	
	

}
